package com.nulldev.util.io.mimer;

import java.io.IOException;
import java.io.InputStream;

import com.nulldev.util.encoding.nHash.nHash;
import com.nulldev.util.java.JVMUtil;
import com.nulldev.util.other.ByteUtils;

/**
 * A simple mime type identifer. <br>
 * WORK IN PROGRESS
 * @author null
 * @since nullUtil 2.7
 */
public class Mimer {
	
	private static final String HEXES = "0123456789ABCDEF";

	private static String getHex(final byte[] raw) {
	    final StringBuilder hex = new StringBuilder(2 * raw.length);
	    for (final byte b : raw) {
	        hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
	    }
	    return hex.toString();
	}
	
	public static Mime identify(final byte[] data) {
		byte[] preMime = ByteUtils.readXBytes(data, 0, (4) - 1);
		final Long mime = (Long) nHash.getHasher("nhash.hash32").hash(data);
		JVMUtil.async_println("Mime: " + mime);
		return null;
	}

	public static Mime identify(final InputStream is) throws IOException {
		byte[] preMime = new byte[4];
		is.read(preMime);
		JVMUtil.async_println("Mime: " + getHex(preMime));
		return null;
	}
	
}
